<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'language' => 'zh-CN',
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
        "@mdm/admin" => "@vendor/mdmsoft/yii2-admin",
    ],
    'defaultRoute'=>'/dashboard/dashboard',
    
    'modules' => [
        
        'contract' => ['class' => 'app\modules\Contract\Bootstrap',],//合同管理
        'dashboard' => ['class' => 'app\modules\Dashboard\Bootstrap',],
        'basic' => ['class' => 'app\modules\Basic\Bootstrap',], //基础信息
        'manage' => ['class' => 'app\modules\Manage\Bootstrap',], //基础信息
        'agreement' => ['class' => 'app\modules\Agreement\Bootstrap',],
        "admin" => ["class" => "mdm\admin\Module",], //管理
    ],

    'as access' => [
        'class' => 'mdm\admin\components\AccessControl',
        'allowActions' => [
            //'/*',
            //'site/logout',
            'admin/*',//允许所有人访问admin节点及其子节点
            '*',
        ], // 后面对权限完善了以后，记得把*改回来！
    ],

    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'UN2c5JBCnMbHl9Do99PhatgAFK5vLY6I',
        ],

        'authManager' => [        
            "class" => 'yii\rbac\DbManager', 
        ],
        'role' => ['class' => 'app\components\Role',],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        // 'user' => [
        //     'identityClass' => 'app\models\User',
        //     'enableAutoLogin' => true,
        // ],
        'user' => [
            'identityClass' => 'mdm\admin\models\User',
            'loginUrl' => ['admin/user/login'],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        
        'urlManager' => [

            'class' => 'codemix\localeurls\UrlManager',
            'languages' => ['en','zh-CN'],
            'enableDefaultLanguageUrlCode' => true,
            'enableLanguagePersistence' => false,

            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],

        'i18n' => [
            'translations' => [
              'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages',
                // 'sourceLanguage' => 'en',
                'fileMap' => [
                   'app' => 'app.php',
                   'app.product' => 'app.product.php',
                   'app.customer' => 'app.customer.php',
                   'app.supplier' => 'app.supplier.php',
                   'app.basic' => 'app.basic.php',
                   'app.admin' => 'app.admin.php',
                   'app.user' => 'app.user.php',
                   'app.cost' => 'app.cost.php',
                   'app.income' => 'app.income.php',
                   'app.tour' => 'app.tour.php',
                ],
              ],
            ],
        ],
        
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
